﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using AuctionSystem.AuctionService;

namespace AuctionSystem
{
    public partial class ShowArt : Form
    {
        Item item;
        private static AuctionServiceClient client;
        User user;
        public ShowArt(Item i, User u)
        {
            InitializeComponent();
            client = new AuctionServiceClient();
            item = i;
            user = u;
            StartUp();
        }
        private void StartUp()
        {
            txtbox_ID.Text = item.ID.ToString();
            txtbox_title.Text = item.Title;
            
            //start date
            if (item.StartDateTime.Date.ToString() != null)
            {
                txtbox_startdate.Text = item.StartDateTime.Date.ToString();
            }
            else
            {
                txtbox_startdate.Text = "Start date not jet set";
            }
            //end date
            if (item.EndDateTime.Date.ToString() != null)
            {
                txtbox_enddate.Text = item.EndDateTime.Date.ToString();
            }
            else
            {
                txtbox_enddate.Text = "End date not jet set";
            }
            //end price
            if(item.EndPrice.ToString() != null)
            {
                txtbox_endPrice.Text = item.EndPrice.ToString();
            }
            else
            {
                txtbox_endPrice.Text = "Auction not jet ended";
            }
            //Active
            if(item.Active == true)
            {
                cheBox_Active.Checked = true;
            }
            else
            {
                cheBox_Active.Checked = false;
            }
            //Description
            if(item.Description != null)
            {
                richTextBox_Desp.Text = item.Description.ToString();
            }
            else
            {
                richTextBox_Desp.Text = "Description is not jet set";
            }
            if (item.StartPrice.ToString() != null)
            { 
            textBox_startPrice.Text = item.StartPrice.ToString();
            }
            else
            {
                textBox_startPrice.Text = "start price does not exist";
            }
            CheckBid();
        }
        private void CheckBid()
        {
            int tembid = client.GetTopBid(item);
            TextBox_CurrentBid.Text = tembid.ToString();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btn_bid_Click(object sender, EventArgs e)
        {
            Bid bid = new Bid();
            bid.User = user;
            if(txtbox_yourBid.Text != null)
            {
                bid.Amount = System.Convert.ToInt32(txtbox_yourBid.Text);
                bid.Item = item;
                client.PlaceBid(bid);
            }
            else
            {
                MessageBox.Show("You have not entered a bid");
            }
        }
            


    }
}
